<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('Syuser')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item v-if="record.bpmStatus === '1'">
                <a @click="startProcess(record)">发起流程</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <sy-user-modal ref="modalForm" @ok="modalFormOk"></sy-user-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import SyUserModal from './modules/SyUserModal'
  import { postAction } from '@/api/manage'

  export default {
    name: 'SyUserList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      SyUserModal
    },
    data () {
      return {
        description: 'Syuser管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'登录账号',
            align:"center",
            dataIndex: 'username'
          },
          {
            title:'真实姓名',
            align:"center",
            dataIndex: 'realname'
          },
          {
            title:'密码',
            align:"center",
            dataIndex: 'password'
          },
          {
            title:'md5密码盐',
            align:"center",
            dataIndex: 'salt'
          },
          {
            title:'头像',
            align:"center",
            dataIndex: 'avatar'
          },
          {
            title:'生日',
            align:"center",
            dataIndex: 'birthday',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'性别(0-默认未知,1-男,2-女)',
            align:"center",
            dataIndex: 'sex'
          },
          {
            title:'电子邮件',
            align:"center",
            dataIndex: 'email'
          },
          {
            title:'电话',
            align:"center",
            dataIndex: 'phone'
          },
          {
            title:'登录会话的机构编码',
            align:"center",
            dataIndex: 'orgCode'
          },
          {
            title:'性别(1-正常,2-冻结)',
            align:"center",
            dataIndex: 'status'
          },
          {
            title:'删除状态(0-正常,1-已删除)',
            align:"center",
            dataIndex: 'delFlag'
          },
          {
            title:'第三方登录的唯一标识',
            align:"center",
            dataIndex: 'thirdId'
          },
          {
            title:'第三方类型',
            align:"center",
            dataIndex: 'thirdType'
          },
          {
            title:'同步工作流引擎(1-同步,0-不同步)',
            align:"center",
            dataIndex: 'activitiSync'
          },
          {
            title:'工号，唯一键',
            align:"center",
            dataIndex: 'workNo'
          },
          {
            title:'职务，关联职务表',
            align:"center",
            dataIndex: 'post'
          },
          {
            title:'座机号',
            align:"center",
            dataIndex: 'telephone'
          },
          {
            title:'身份（1普通成员 2上级）',
            align:"center",
            dataIndex: 'userIdentity'
          },
          {
            title:'负责部门',
            align:"center",
            dataIndex: 'departIds'
          },
          {
            title:'设备ID',
            align:"center",
            dataIndex: 'clientId'
          },
          {
            title:'上次登录选择租户ID',
            align:"center",
            dataIndex: 'loginTenantId'
          },
          {
            title:'流程入职离职状态',
            align:"center",
            dataIndex: 'bpmStatus'
          },
          {
            title:'IP',
            align:"center",
            dataIndex: 'ip'
          },
          {
            title:'部门',
            align:"center",
            dataIndex: 'bm'
          },
          {
            title:'身份',
            align:"center",
            dataIndex: 'sf'
          },
          {
            title:'glname',
            align:"center",
            dataIndex: 'glname'
          },
          {
            title:'ryxm',
            align:"center",
            dataIndex: 'ryxm'
          },
          {
            title:'dlrbmbm',
            align:"center",
            dataIndex: 'dlrbmbm'
          },
          {
            title:'dlrdwbm',
            align:"center",
            dataIndex: 'dlrdwbm'
          },
          {
            title:'网络类型',
            align:"center",
            dataIndex: 'wllx'
          },
          {
            title:'state',
            align:"center",
            dataIndex: 'state'
          },
          {
            title:'sfjzroleid',
            align:"center",
            dataIndex: 'sfjzroleid'
          },
          {
            title:'stateall',
            align:"center",
            dataIndex: 'stateall'
          },
          {
            title:'jwhcy',
            align:"center",
            dataIndex: 'jwhcy'
          },
          {
            title:'yejcg',
            align:"center",
            dataIndex: 'yejcg'
          },
          {
            title:'tlgl',
            align:"center",
            dataIndex: 'tlgl'
          },
          {
            title:'userid',
            align:"center",
            dataIndex: 'userid'
          },
          {
            title:'ycerror',
            align:"center",
            dataIndex: 'ycerror'
          },
          {
            title:'是否在线',
            align:"center",
            dataIndex: 'online'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/syuser/syUser/list",
          delete: "/syuser/syUser/delete",
          deleteBatch: "/syuser/syUser/deleteBatch",
          exportXlsUrl: "/syuser/syUser/exportXls",
          importExcelUrl: "syuser/syUser/importExcel",
          startProcess: '/act/process/extActProcess/startMutilProcess'
        },
        //代码生成后需手动设置流程编码
        flowCode: 'dev_sys_user_001',
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      startProcess(record){
        this.$confirm({
          title:'提示',
          content:'确认提交流程吗?',
          onOk:()=>{
            let params = {
              flowCode: this.flowCode,
              id: record.id,
              formUrl: 'syuser/modules/SyUserForm',
              formUrlMobile: ''
            }
            postAction(this.url.startProcess, params).then(res=>{
              if(res.success){
                this.$message.success(res.message);
                this.loadData();
                this.onClearSelected();
              }else{
                this.$message.warning(res.message);
              }
            }).catch((e)=>{
              this.$message.warning('不识别的请求!');
            })
          }
        })
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'username',text:'登录账号'})
        fieldList.push({type:'string',value:'realname',text:'真实姓名'})
        fieldList.push({type:'string',value:'password',text:'密码'})
        fieldList.push({type:'string',value:'salt',text:'md5密码盐'})
        fieldList.push({type:'string',value:'avatar',text:'头像'})
        fieldList.push({type:'date',value:'birthday',text:'生日'})
        fieldList.push({type:'int',value:'sex',text:'性别(0-默认未知,1-男,2-女)'})
        fieldList.push({type:'string',value:'email',text:'电子邮件'})
        fieldList.push({type:'string',value:'phone',text:'电话'})
        fieldList.push({type:'string',value:'orgCode',text:'登录会话的机构编码'})
        fieldList.push({type:'int',value:'status',text:'性别(1-正常,2-冻结)'})
        fieldList.push({type:'int',value:'delFlag',text:'删除状态(0-正常,1-已删除)'})
        fieldList.push({type:'string',value:'thirdId',text:'第三方登录的唯一标识'})
        fieldList.push({type:'string',value:'thirdType',text:'第三方类型'})
        fieldList.push({type:'int',value:'activitiSync',text:'同步工作流引擎(1-同步,0-不同步)'})
        fieldList.push({type:'string',value:'workNo',text:'工号，唯一键'})
        fieldList.push({type:'string',value:'post',text:'职务，关联职务表'})
        fieldList.push({type:'string',value:'telephone',text:'座机号'})
        fieldList.push({type:'int',value:'userIdentity',text:'身份（1普通成员 2上级）'})
        fieldList.push({type:'string',value:'departIds',text:'负责部门'})
        fieldList.push({type:'string',value:'clientId',text:'设备ID'})
        fieldList.push({type:'int',value:'loginTenantId',text:'上次登录选择租户ID'})
        fieldList.push({type:'string',value:'bpmStatus',text:'流程入职离职状态'})
        fieldList.push({type:'string',value:'ip',text:'IP'})
        fieldList.push({type:'string',value:'bm',text:'部门'})
        fieldList.push({type:'string',value:'sf',text:'身份'})
        fieldList.push({type:'string',value:'glname',text:'glname'})
        fieldList.push({type:'string',value:'ryxm',text:'ryxm'})
        fieldList.push({type:'string',value:'dlrbmbm',text:'dlrbmbm'})
        fieldList.push({type:'string',value:'dlrdwbm',text:'dlrdwbm'})
        fieldList.push({type:'string',value:'wllx',text:'网络类型'})
        fieldList.push({type:'string',value:'state',text:'state'})
        fieldList.push({type:'string',value:'sfjzroleid',text:'sfjzroleid'})
        fieldList.push({type:'string',value:'stateall',text:'stateall'})
        fieldList.push({type:'string',value:'jwhcy',text:'jwhcy'})
        fieldList.push({type:'string',value:'yejcg',text:'yejcg'})
        fieldList.push({type:'string',value:'tlgl',text:'tlgl'})
        fieldList.push({type:'string',value:'userid',text:'userid'})
        fieldList.push({type:'string',value:'ycerror',text:'ycerror'})
        fieldList.push({type:'int',value:'online',text:'是否在线'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>